package Config::System::t::Section;

use strict;
use warnings;
use Test::More;
use IO::All -utf8;
use Test::Exception;
use aliased 'Config::System::Section';
use aliased 'Config::System::File';

use base 'Test::Class';

sub no_files_with_default: Test {
     my $iut = Section->new(name => 'Foo', files => []);
     $iut->add_property(Bar => {isa => 'Str', default => 'baz'});
     is $iut->get('Bar'), 'baz';
}

sub no_files_no_default_with_set: Test {
     my $iut = Section->new(name => 'A', files => []);
     $iut->add_property(B => {isa => 'Num'});
     $iut->set(B => 123);
     is $iut->get('B'), 123;
}

sub no_files_no_default_with_set_expression_if_1st: Test {
     my $iut = Section->new(name => 'A', files => []);
     $iut->add_property(B => {isa => 'Num'});
     $iut->set_expression_if_1st(B => 0);
     is $iut->get('B'), 0;
}

sub one_file_no_default: Test {
    my $path = 'x.properties';
    io($path)->write("[X]\nY=21*2");
     my $iut = Section->new(
         name  => 'X',
         files => [File->new(path => $path)],
     );
     $iut->add_property(Y => {isa => 'Num'});
     $iut->read_property_from_files($iut->properties->{Y});
     is $iut->get('Y'), 42;
     io($path)->unlink;
}

sub clone_no_files: Test(4) {
     my $iut = Section->new(name => 'Foo', files => []);
     $iut->add_property(Bar => {isa => 'Num'});
     $iut->set_expression(Bar => '2 * 3');
     my $clone = $iut->clone([]);
     is $iut->get('Bar'), 6;
     is $clone->get('Bar'), 6;
     $clone->set_expression(Bar => '3 * 3');
     is $iut->get('Bar'), 6;
     is $clone->get('Bar'), 9;
}

1;


